package com.vivz.baby.proxy;

import java.util.List;

import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import android.util.Log;

import com.vivz.baby.persistence.model.Logs;

public class LogProxy {

    private static final String TAG = "LogProxy";

    public static final void logData(final String url, com.vivz.baby.persistence.model.Log log) {

        try {
            RestTemplate restTemplate = new RestTemplate();
            List<HttpMessageConverter<?>> messageConverters = restTemplate.getMessageConverters();
            messageConverters.add(new MappingJackson2HttpMessageConverter());

            com.vivz.baby.persistence.model.Log savedLog = restTemplate.postForObject(url, log, com.vivz.baby.persistence.model.Log.class);
            Log.i(TAG, "Saved log successfully: [" + savedLog + "]");

        } catch (Exception e) {
            Log.e(TAG, e.getMessage(), e);
        }
    }
    

    public static final List<com.vivz.baby.persistence.model.Log> getAllLogs(String url) {

		RestTemplate restTemplate = new RestTemplate();
		List<HttpMessageConverter<?>> messageConverters = restTemplate.getMessageConverters();
		messageConverters.add(new MappingJacksonHttpMessageConverter());

		Logs body = restTemplate.postForObject(url, null, Logs.class);

		return body.getLogs();
	}

}
